﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RegExStudio.RegExStudioEventArgs;

namespace RegExStudio.UserControls
{
    /// <summary>
    /// Control das den Namen der RegEx anzeigt/ändert
    /// </summary>
    public partial class CtrlName : CtrlGroup
    {
        /// <summary>
        /// Setzt/Liest den Namen der RegEx aus
        /// </summary>
        public string RegExName
        {
            get { return txtName.Text; }
            set { txtName.Text = value; }
        }

        /// <summary>
        /// ctor
        /// </summary>
        public CtrlName()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Control wird geladen
        /// Eingabecontrol-Hintergrundfärbung aktivieren
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CtrlName_Load(object sender, EventArgs e)
        {
            txtName.Enter += new EventHandler(Control_Enter);
            txtName.Leave += new EventHandler(Control_Leave);
        }

        /// <summary>
        /// Der Name wurde geändert
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtName_TextChanged(object sender, EventArgs e)
        {
            OnNameChanged(txtName.Text);
        }

        /// <summary>
        /// EventHandler für Änderung des Namens
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public delegate void NameChangedEventHandler(object sender, NameChangedEventArgs e);

        /// <summary>
        /// Event das ausgelöst wird, wenn der Name der RegEx geändert wurde
        /// </summary>
        public event NameChangedEventHandler NameChanged;
        
        /// <summary>
        /// Feuert das Event, wenn der Name geändert wurde
        /// </summary>
        /// <param name="name"></param>
        protected virtual void OnNameChanged(string name)
        {
            if (NameChanged != null)
            {
                NameChanged(this, new NameChangedEventArgs(name));
            }
        }

    }
}
